const calculateEntropy = (probabilities) => {
    const entropy = probabilities.reduce((entropy, p) => {
      if (p === 0) return entropy;
      return entropy - p * Math.log2(p);
    }, 0);
    return Number(entropy.toFixed(3)); // 将结果四舍五入到3位小数并转回数字
}

module.exports = { calculateEntropy };